import request from '@/utils/request'

// 查询广告素材列表
export function listMaterial(query) {
  return request({
    url: '/advertisement/material/list',
    method: 'get',
    params: query
  })
}

// 查询广告素材详细
export function getMaterial(materialId) {
  return request({
    url: '/advertisement/material/' + materialId,
    method: 'get'
  })
}

// 新增广告素材
export function addMaterial(data) {
  return request({
    url: '/advertisement/material',
    method: 'post',
    data: data
  })
}

// 修改广告素材
export function updateMaterial(data) {
  return request({
    url: '/advertisement/material',
    method: 'put',
    data: data
  })
}

// 删除广告素材
export function delMaterial(materialId) {
  return request({
    url: '/advertisement/material/' + materialId,
    method: 'delete'
  })
}

// 批量删除广告素材
export function delMaterials(materialIds) {
  return request({
    url: '/advertisement/material/' + materialIds,
    method: 'delete'
  })
}

// 启用/停用广告素材
export function toggleMaterialStatus(materialId, status) {
  return request({
    url: '/advertisement/material/status',
    method: 'put',
    data: {
      materialId: materialId,
      status: status
    }
  })
}

// 上传广告素材文件
export function uploadMaterial(data) {
  return request({
    url: '/advertisement/material/upload',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 导出广告素材
export function exportMaterial(query) {
  return request({
    url: '/advertisement/material/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  })
}

// 获取素材类型字典
export function getMaterialTypes() {
  return request({
    url: '/advertisement/material/types',
    method: 'get'
  })
}

// 预览素材
export function previewMaterial(materialId) {
  return request({
    url: '/advertisement/material/preview/' + materialId,
    method: 'get'
  })
}
